package com.mybatiscore.jiaocheng.d03mybatis查询专项;

import com.mybatiscore.Mapper.StudentMapper;
import com.mybatiscore.POJO.Student;
import com.mybatiscore.Util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

public class d01返回POJO {
    //返回单个POJO
    @Test
    public void onePojo(){
        SqlSession sqlSession = SqlSessionUtil.openSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        Student student = mapper.selectById1(1L);
        System.out.println(student);
        sqlSession.close();
    }

    //返回多个POJO
    @Test
    public void onePojoAll(){
        SqlSession sqlSession = SqlSessionUtil.openSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        List<Student> students = mapper.selectAll();
        for (Student s:students
             ) {
            System.out.println(s);
        }
        sqlSession.close();
    }

    //模糊查询
    @Test
    public void moHu(){
        SqlSession sqlSession = SqlSessionUtil.openSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        List<Student> students = mapper.selectNameLike("李");
        for (Student s:students
        ) {
            System.out.println(s);
        }
        sqlSession.close();
    }
}
